{% set originalValue = originalValue is defined ? originalValue : value %}
{% set toggleableChecked = field.toggleable and (originalValue is not null and originalValue is not empty) %}
{% set isDisabledToggleable = field.toggleable and not toggleableChecked %}
{% set value = (is_object(value) or value is null ? field.default : value) %}
{% set errors = attribute(form.messages, field.name) %}

{% block field %}
    <div class="form-field {% if field.outerclasses is defined %} {{ field.outerclasses }}{% endif %}{% if errors %} has-errors{% endif %} {% block outer_field_classes %}{% endblock %}">
        {% block contents %}
            {% if field.label is not same as(false) %}
                <div class="form-label">
                    <label class="inline" {% if field.id is defined %}for="{{ field.id|e }}" {% endif %} >
                    {% block label %}
                        {% if field.help %}
                        <span class="tooltip" data-asTooltip-position="w" title="{{ field.help|t|e }}">{{ field.label|default(field.name|capitalize)|t }}</span>
                        {% else %}
                        {{ field.label|default(field.name|capitalize)|t }}
                        {% endif %}
                        {{ field.validate.required in ['on', 'true', 1] ? '<span class="required">*</span>' }}
                    {% endblock %}
                    </label>
                </div>
            {% endif %}
            <div class="form-data"
                {% block global_attributes %}
                data-grav-field="{{ field.type }}"
                data-grav-disabled="{{ originalValue is null ? 'true' : 'false' }}"
                data-grav-default="{{ field.default|json_encode()|e('html_attr') }}"
                {% endblock %}
            >
                {% block group %}
                    {% block input %}
                        <div class="form-input-wrapper {{ field.size }} {{ field.wrapper_classes }}">
                            {% block prepend %}{% endblock prepend %}
                            <input
                                {# required attribute structures #}
                                name="{{ (scope ~ field.name)|fieldName }}"
                                value="{{ value|join(', ')|e('html_attr') }}"
                                {# input attribute structures #}
                                {% block input_attributes %}
                                    {% if field.classes is defined %}class="{{ field.classes }}" {% endif %}
                                    {% if field.id is defined %}id="{{ field.id|e }}" {% endif %}
                                    {% if field.style is defined %}style="{{ field.style|e }}" {% endif %}
                                    {% if field.disabled or isDisabledToggleable %}disabled="disabled"{% endif %}
                                    {% if field.placeholder %}placeholder="{{ field.placeholder|t }}"{% endif %}
                                    {% if field.autofocus in ['on', 'true', 1] %}autofocus="autofocus"{% endif %}
                                    {% if field.novalidate in ['on', 'true', 1] %}novalidate="novalidate"{% endif %}
                                    {% if field.readonly in ['on', 'true', 1] %}readonly="readonly"{% endif %}
                                    {% if field.autocomplete in ['on', 'off'] %}autocomplete="{{ field.autocomplete }}"{% endif %}
                                    {% if field.validate.required in ['on', 'true', 1] %}required="required"{% endif %}
                                    {% if field.validate.pattern %}pattern="{{ field.validate.pattern|e }}"{% endif %}
                                    {% if field.validate.message %}title="{{ field.validate.message|t|e }}"
                                    {% elseif field.title is defined %}title="{{ field.title|t|e }}" {% endif %}
                                {% endblock %}
                            />
                            {% block append %}{% endblock append %}
                            {% if form.inline_errors and errors %}
                                <div class="form-errors">
                                    {% for error in errors %}
                                        <p class="form-message"><i class="fa fa-exclamation-circle"></i> {{ error }}</p>
                                    {% endfor %}
                                </div>
                            {% endif %}
                        </div>
                    {% endblock %}
                {% endblock %}
                {% if field.description %}
                    <div class="form-extra-wrapper {{ field.size|e }} {{ field.wrapper_classes }}">
                        <span class="form-description">{{ field.description|raw }}</span>
                    </div>
                {% endif %}

            </div>
        {% endblock %}
    </div>
{% endblock %}
